package cn.ssm.test.controller;

import java.awt.image.BufferedImage;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.google.code.kaptcha.Producer;

import cn.ssm.test.model.Whisper;
import cn.ssm.test.service.IWhisperService;

@Controller    
@RequestMapping("/whisper")  
public class WhisperController {

	@Autowired
	private IWhisperService whisperService;
	
	@Autowired
	private Producer captchaProducer;
	
	
	@RequestMapping("/info")
	public void getWhisperInfo(HttpServletRequest request ,HttpServletResponse response, Model  model) throws IOException{
		
		Whisper whisper =whisperService.getWhisperInfo();
		//验证码
		String text = captchaProducer.createText();
		BufferedImage image = captchaProducer.createImage(text);	
		model.addAttribute("whisper", whisper);
		ServletOutputStream out = response.getOutputStream();
		ImageIO.write(image, "jpg", out);
			
	}
	
	@RequestMapping("/love")
	public String toIndex(HttpServletRequest request ,HttpServletResponse response, Model  model){
		return "index";
	}
}
